import {defineStore} from "pinia";
import {useGet} from "@/hooks";
import {setToken} from "@/util";

export const useBaseStore = defineStore("base", () => {
    const userId = ref<number>(0)

    async function getUserInfo() {
        await useGet({
            url: "/v1/user/base",
            params: {},
            success: (data) => {
                console.log(data)
                userId.value = data.id
            },
            fail: (msg, code) => {
                if(code === 1400) {
                    setToken("")
                    location.reload()
                }
            }
        }, true)
    }

    return {
        userId,
        getUserInfo
    }
})